<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ page import="weaver.hrm.HrmUserVarify"%>
<%@ page import="weaver.hrm.User"%>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="weaver.general.*" %>
<%@ page import="weaver.general.Util" %>
<jsp:useBean id="RecordSet" class="weaver.conn.RecordSet" scope="page" />
<jsp:useBean id="rs" class="weaver.conn.RecordSet" scope="page" />
<%@ page import="java.net.URLDecoder"%>
<%

BaseBean baseBean = new BaseBean();
RecordSet res = new RecordSet();
//获取当前登录用户
User user = HrmUserVarify.getUser (request , response) ;
if(user == null)  return ;
int departmentid = user.getUserDepartment();
int userId =  user.getUID();
baseBean.writeLog("================"+userId);
baseBean.writeLog("================"+departmentid);
//查询当前登录人所拥有的权限
//根据角色查询   总经理角色id=46   财务经理角色id=53
String sfrUrl = "http://125.35.221.252:8075/WebReport/ReportServer?reportlet=";
String sfrSrc = "";//iframe超链接地址
String sfrTitle = "";//报表名称
String isiframe = "";//是否本页面iframe打开
//帆软报表的路径
sfrSrc = "gongdan_kehubu.cpt";
String sql = "";

String root = "&root=0";//默认为0，如果没有传递root值就全部数据不可查

//情况1:总经理财务经理可以查看所有报表
sql = "select * from hrmrolemembers where resourceid='"+userId+"' and (roleid='46' or roleid='53')";
res.execute(sql);
if(res.next()){
	//直接跳转页面   查询所有的报表
	root = "&root=1";
	sfrUrl = sfrUrl+sfrSrc+"&__bypagesize__=false&userId="+userId+root;
	if(!"0".equals(isiframe)){
		response.sendRedirect(sfrUrl);
		return;
	}
} 


//return;
//情况3:客户部经理只能看到本部门的
//获取所有市场部的人员及所有上级id
sql = " select distinct departmentid from hrmresource where departmentid in(4,13,18) and managerstr like '%,"+userId+",%'";
res.execute(sql);
if(res.next()){
	root = "&root=2";
	sfrUrl = sfrUrl+sfrSrc+"&__bypagesize__=false&userId="+userId+root;
	if(!"0".equals(isiframe)){
		response.sendRedirect(sfrUrl);
		return;
	}
}

//情况2:AE即发起人只能查看自己的报表
if(departmentid == 4 || departmentid == 13 || departmentid == 18){
	root = "&root=3";
	//直接跳转页面   传入本人id 只查看本人的
	sfrUrl = sfrUrl+sfrSrc+"&__bypagesize__=false&userId="+userId+root;
	if(!"0".equals(isiframe)){
		response.sendRedirect(sfrUrl);
		return;
	}
}

String other = "error.jsp";
response.sendRedirect(other);
%>
<!DOCTYPE html>   
<html>       
<head>       
<title><%=sfrTitle%></title>       
<script type="text/javascript"> 
var sfrSrc = "<%=sfrSrc%>";
if(sfrSrc==""){
	alert("无法正确解析找到相应的帆软报表文件,请不要修改地址栏的参数")
	window.close();
}
//cjkEncode方法的实现代码，放在网页head中或者用户自己的js文件中  
var sfrUrl = "<%=sfrUrl%>";
function cjkEncode(text) {                                                                             
  if (text == null) {          
    return "";          
  }          
  var newText = "";          
  for (var i = 0; i < text.length; i++) {          
    var code = text.charCodeAt (i);           
    if (code >= 128 || code == 91 || code == 93) {  //91 is "[", 93 is "]".          
      newText += "[" + code.toString(16) + "]";          
    } else {          
      newText += text.charAt(i);          
    }          
  }          
  return newText;          
}      
function autoLoad() {  
  var addr = cjkEncode(sfrUrl);   
  //var addr = sfrUrl;   
  document.getElementById("reportFrame").src = addr;   
}   
window.onload = autoLoad; 
</script>       
</head>       
<body style="margin:0px;">        
<iframe id="reportFrame"  src="" style="width:100%;height:800px;" ></iframe>       
</body>       
</html> 